<template>
	<view class="page">
		<view class="nav-style" :style="{ height: navHeight + 'px' }">
			<view style="width: 50rpx; height: 100%" @click="back">
				<image class="back-img" src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/back.png" mode="aspectFit" :style="{ top: statusBarHeight + 'px' }"></image>
			</view>
			<image
				class="small-logo"
				src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/logo-white.png"
				mode="aspectFit"
				:style="{ 'padding-top': statusBarHeight + 'px' }"
			></image>
		</view>
		<view v-if="[4, 5].includes(info.step)" class="process-wrap" :style="{ 'padding-top': navHeight + 20 + 'px' }">
			<process :active="info.step" :steps="collectionStepsData" />
		</view>
		<!--    <image class="header" src="/static/image/header.png" mode="aspectHeightFit" />-->

		<view class="wrap" :style="{ 'margin-top': [1, 2, 3, 6, 7].includes(info.step) ? navHeight + 'px' : '' }">
			<test-check ref="testCheck" :info="info" :time="times" :device-number="deviceNumber" @back="back" @next="onConfirm" @Close="Shutdown" />
		</view>

		<!-- 有反应弹窗 -->
		<uni-popup ref="popup" :mask-click="false" :is-mask-click="false" type="center" borderRadius="13px 13px 13px 13px">
			<view class="popup-wrap" style="border-radius: 26rpx">
				<!-- <image class="fixed" src="../../static/image/zixun.png" mode="" @click="skip"></image> -->
				<image class="popup-bg" src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/agree-box.png" style="border-radius: 26rpx" mode="aspectFit" />
				<view class="popup-container">
					<view class="popup-title">
						<image class="popup-img" src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/tips-icon.png" mode="aspectFit" />
						<view class="popup-text">温馨提示</view>
					</view>
					<view class="popup-content">
						您好，根据本次检测结果，您的HIV抗体筛查检测结果显示为"有反应(待复查)"，提示可能检测到了 HIV 抗体，但这并不等同于确诊感染
						HIV，在此之前请您不必过于担忧。某些因素(如自身免疫性疾病、近期接种疫苗等)可能会引起检测结果的交叉反应，导致假阳性结果的出现。为明确诊断，您需要前往当地的艾滋病确证实验室进行进一步的确证检测，以最终确定是否感染
						HIV。即使确证检测结果为阳性，通过规范的抗病毒治疗，完全可以获得与常人基本无异的寿命和生活品质。
						<br />
						注意事项 1. 本检测结果仅作为初步筛查依据，不能单独作为 HIV
						感染的最终诊断结论。检测结果的解释需结合个人流行病学史、临床症状以及其他相关检测结果进行综合分析。 2.
						由于窗口期、检测方法局限性等客观因素的存在，可能导致检测结果出现偏差。 3.
						请您正确理解检测结果，切勿因对检测结果的误解而采取不当行为或产生不必要的恐慌。若您对检测结果有任何疑问，可及时咨询专业的医务人员或艾滋病防治机构。
					</view>
					<view class="popup-btn-wrap">
						<!-- <view class="popup-btn cancel" @click="onCancel">不需要</view> -->
						<view class="popup-btn need" style="width: 80%" @click="onNeed">需要</view>
						<!-- <view class="popup-btn-close cancel" @click="Shutdown">关机</view> -->
					</view>
				</view>
			</view>
		</uni-popup>

		<!-- 无反应弹窗 -->
		<uni-popup ref="popup2" :mask-click="false" :is-mask-click="false" type="center" borderRadius="13px 13px 13px 13px">
			<view class="popup-wrap2" style="border-radius: 13px">
				<!-- <image class="fixed" src="../../static/image/zixun.png" mode="" @click="skip"></image> -->
				<image class="popup-bg" style="border-radius: 13px" src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/agree-box.png" mode="aspectFit" />
				<view class="popup-container">
					<view class="popup-title">
						<image class="popup-img" src="https://yun.shlxkj.info:44300/艾瑞测/小程序/static/img/step-result-normal.png" mode="aspectFit" />
						<view class="popup-text">温馨提示</view>
					</view>
					<view class="popup-content">
						您好，根据本次检测结果，您的HIV抗体筛查结果显示为“阴性”，表明在本次检测中未检测到 HIV 抗体，您可能并未感染
						HIV。请您继续保持健康的性行为。但需注意，以下原因也可能导致阴性结果：
						<br />
						1.处于窗口期：HIV
						感染后的前2-6周，人体可能尚未产生足够量的抗体，现有检测方法可能无法检出。若您最后一次无保护性行为距今不足6周，本次检测结果可能为阴性。在此情况下，建议您在距离最后一次无保护性行为满6周后再次进行检测，以确保结果的准确性。
						2.检测方法局限性：由于检测方法存在一定的局限性，少数感染 HIV 的人群可能无法通过该检测方法检出阳性，从而出现假阴性结果。因此，本次检测结果不能完全排除您感染
						HIV 的可能。建议您在 6 周后再次进行检测，或前往当地各自愿咨询检测门诊及医疗机构抽取静脉血进行检测，以进一步确认。
						<br />
						注意事项 1. 本检测结果仅作为初步筛查依据，不能单独作为 HIV
						感染的最终诊断结论。检测结果的解释需结合个人流行病学史、临床症状以及其他相关检测结果进行综合分析。 2.
						由于窗口期、检测方法局限性等客观因素的存在，可能导致检测结果出现偏差。 3.
						请您正确理解检测结果，切勿因对检测结果的误解而采取不当行为或产生不必要的恐慌。若您对检测结果有任何疑问，可及时咨询专业的医务人员或艾滋病防治机构。
					</view>
					<view class="popup-btn-wrap2">
						<view class="popup-btn-close" @click="closePopup2">关闭</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import store from '@/store';
import TestCheck from '@/page-defense/home/components/test-check/index.vue';
import Process from '../../components/process/index.vue';
import { ab2hex, sleep, debounce } from '@/utils/util.js';
import {
	GetReleted,
	Getresult,
	DecryptMac,
	CreateReleted,
	ConvertCoordinate,
	UpReagentResult,
	aesDecryptjieguozhi,
	aesDecrypt2,
	AESEncrypt,
	AESDecrypt,
	UpdateReagentResult,
	aesDecryptGetAPiyuzhi,
	InsertSubscribeinform,
	Base64
} from '@/utils/api.js';
const baseSecret = '4B65487561BFC6';
// const HANDLE_0x1800 = '00001800-0000-1000-8000-00805F9B34FB'
// const HANDLE_0x2A00 = '00002A00-0000-1000-8000-00805F9B34FB'
const HANDLE_0x9000 = '00009000-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9001 = '00009001-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9002 = '00009002-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9003 = '00009003-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9004 = '00009004-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9005 = '00009005-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9006 = '00009006-0000-1000-8000-00805F9B34FB';
const HANDLE_0x9007 = '00009007-0000-1000-8000-00805F9B34FB';
let that = null;
export default {
	name: 'Home',
	components: {
		TestCheck,
		Process
	},
	data() {
		return {
			GetQuestionType: false,
			HFX: '',
			JG: false,
			JG_2: 0,
			weiwancheng: false,
			managePhone: '',
			gps: false,
			processIndex: 1,
			isStartDiscovery: false,
			timer: null,
			checkTimer: null,
			resultTimer: null,
			navHeight: '',
			statusBarHeight: '',
			DetectionType: '',
			times: 0,
			step: 1,
			info: {},
			blueDeviceList: [],
			blueDeviceList_1: [],
			process: [],
			deviceNumber: '', // 设备编号
			scanMac: '', // mac地址
			deviceId: '',
			serviceId: '',
			characteristicId: '',
			key: '',
			new_meg: false,
			collectionStepsData: [
				{
					step: 2,
					name: '采血'
				},
				{
					step: 3,
					name: '检测'
				}
			],
			stepData: [
				{
					step: 1,
					steps: [
						{
							step: 1,
							imageNum: 1,
							name: '材料检查',
							image: 'step-check.png',
							content: ['请检查电子检测盒、采血针、滴管、酒精棉片、缓冲液等内容物是否齐全。']
						},
						{
							step: 2,
							imageNum: 2,
							name: '操作准备',
							image: 'step-operate.png',
							content: [
								'1、洗手并消毒，在做测试前，手需要完全擦干；',
								'2、将电子检测盒取出，放在室温中；',
								'3、确认电子检测盒的效期在可使用范围内；',
								'4、在撕口处打开铝箔袋，取出电子检测盒，滴液口向上，平放于桌面。'
							]
						},
						{
							step: 3,
							imageNum: 3,
							name: '开启设备',
							image: 'step-turn-on.png',
							content: ['1、请拔出电池阻断塑料片；', '2、将电子检测盒放在距离手机50cm以内；', '3、观看电子检测盒指示灯是否闪烁。']
						}
						// {
						// 	step: 4,
						// 	imageNum: 4,
						// 	name: '扫码连接',
						// 	image: 'step-connect.png',
						// 	content: ['1、寻找到电子检测盒上二维码；', '2、请点击下方扫一扫；', '3、扫描二维码进行蓝牙连接。']
						// }
					],
					operateName: '扫一扫'
				},
				// 连接失败
				{
					step: 2, // 5
					imageNum: 5,
					name: '连接电子检测盒',
					contentTitle: '请按以下说明进行检查',
					image: 'step-fail.png',
					imageDesc: '连接失败！',
					content: [
						'1、保持电子检测盒在开机状态；',
						'2、检查手机蓝牙，保持开启状态；',
						'3、将手机与电子检测盒尽量靠近，完成蓝牙配对；',
						'4、电子检测盒未连接到其他的手机'
					],
					operateName: '重新扫描'
				},
				// 连接成功
				{
					step: 3, // 6
					imageNum: 6,
					name: '连接电子检测盒',
					image: 'step-success.png',
					custom: true,
					imageDesc: '连接成功！',
					operateName: '下一步'
				},
				{
					step: 4, // 7
					imageNum: 7,
					name: '指尖血采集',
					image: 'step-collection.png',
					content: ['先用酒精棉片擦拭取血部位，待酒精挥发后采用一次性采血针刺破皮肤采血，用滴管吸取血液。'],
					operateName: '下一步'
				},
				{
					step: 5, // 8
					imageNum: 8,
					name: '加样检测',
					image: 'step-add.png',
					content: ['用滴管吸取一定量的血液样本，然后垂直滴入2滴样本（约 50μl）到加样孔中，并滴加两滴（约 80μl）缓冲液。'],
					operateName: '开始检测'
				},
				{
					step: 6, // 9
					imageNum: 9,
					name: '倒计时',
					contentTitle: '请按以下说明进行',
					content: ['1、请保持电子检测盒平放，耐心等待；', '2、请勿退出应用程序；', '3、请勿将手机拿开检测仪超过50cm的距离。'],
					operateName: '',
					timer: 0
				},
				{
					step: 7, // 10
					imageNum: 10,
					name: '检测结果',
					contentTitle: '检测结果说明',
					content: ['检测完成后，请使用碘伏消毒电子检测盒及滴管，并将电子检测盒、滴管以及其他组件放置于废弃物袋中，并密封。'],
					operateName: '',
					result: 0
				}
			],
			OperationDataId: '',
			up_type: false,
			get_result: false,
			error_show:false,
		};
	},
	beforeDestroy() {
		that = null;
		this.resultTimer = null;
		this.timer = null;
	},
	onUnload() {
		this.close();
		this.step = 1;
		this.info = this.stepData[this.step - 1];
	},
	onHide() {
		console.log('用户隐藏了小程序');
		// this.close()
		// this.step = 1
		// this.info = this.stepData[this.step - 1]
	},
	onLoad(op) {
		this.weiwancheng = false;
		this.get_result = false;
		this.JG = false;
		this.JG_2 = 0;
		this.error_show=false;
		this.managePhone = op.phone;
		this.getLocation();
		that = this;

		this.info = this.stepData[this.step - 1];
		//获取手机系统的信息（在这主要是获取状态栏和胶囊的高度）
		uni.getSystemInfo({
			success: (e) => {
				// this.compareVersion(e.SDKVersion, '2.5.0')
				let statusBar = 0;
				let customBar = 0;

				// #ifdef MP
				statusBar = e.statusBarHeight;
				customBar = e.statusBarHeight + 45;
				if (e.platform === 'android') {
					// this.$store.commit('SET_SYSTEM_IOSANDROID', false)
					customBar = e.statusBarHeight + 50;
				}
				// #endif

				// #ifdef MP-WEIXIN
				statusBar = e.statusBarHeight;
				// @ts-ignore
				const custom = wx.getMenuButtonBoundingClientRect();
				customBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif

				// #ifdef APP-PLUS
				console.log('app-plus', e);
				statusBar = e.statusBarHeight;
				customBar = e.statusBarHeight + 45;
				// #endif

				// #ifdef H5
				statusBar = 0;
				customBar = e.statusBarHeight + 45;
				// #endif

				// 这里你可以自己决定存放方式，建议放在store中，因为store是实时变化的
				this.statusBarHeight = statusBar;
				this.navHeight = customBar;
			}
		});
	},
	onShow() {
		if (this.timer && this.step === 6) {
			this.read(HANDLE_0x9007); // 读取结果：0x9007返回的检测结果剩余时间
		}
	},
	watch: {
		// 监听 `step` 的变化
		step(newValue, oldValue) {
			// 当 `step` 不等于 1 时，执行相关操作
			if (newValue == 1) {
				console.log('监听到当前step为1', this.step);
			}
		}
	},
	methods: {
		closePopup2() {
			this.$refs.popup2.close();
		},
		back: debounce(() => {
			if (that.step === 1) {
				uni.reLaunch({
					url: '/pages/module/index'
				});
				return;
			} else if ([3, 6].includes(that.step)) {
				// 扫一扫
				if (that.$store.state.wenjuan_show == true) {
					that.$store.commit('$uStore', {
						name: 'wenjuan_show',
						value: false
					});
					return;
				} else {
					that.step = 1;
					that.info = that.stepData[that.step - 1];
					that.close();
					return;
				}
			} else if (that.step === 7) {
				that.close();
				uni.navigateBack();
				return;
			}
			that.step--;
			that.info = that.stepData[that.step - 1];
		}, 500),
		onConfirm: debounce(async (e) => {
			console.log(e, '表单结果');
			that.$store.commit('$uStore', {
				name: 'docterphone',
				value: e.docterphone
			});
			that.$store.commit('$uStore', {
				name: 'account',
				value: e.userphone.trim()
			});
			that.$store.commit('$uStore', {
				name: 'name',
				value: e.username
			});
			that.$store.commit('$uStore', {
				name: 'age',
				value: e.userage
			});
			that.$store.commit('$uStore', {
				name: 'sex',
				value: e.usergender
			});
			that.$store.commit('$uStore', {
				name: 'homeAddress',
				value: e.userlive
			});
			console.log(that.step);
			if (that.step === 1) {
				if (that.gps === false) {
					// console.log('当前未授权定位');
					that.getLocation();
				} else if (that.gps === true) {
					// if(that.$store.state.account==''){
					// 	uni.showToast({
					// 		title: '请填写用户手机号',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return
					// }
					// // 使用正则表达式判断手机号格式
					// const phonePattern = /^1[3-9]\d{9}$/;
					// if (!phonePattern.test(that.$store.state.account)) {
					//   uni.showToast({
					//     title: '手机号格式不正确',
					//     icon: 'none',
					//     duration: 2000
					//   });
					//   return;
					// }

					if (that.get_result == false) {
						that.up_type = false;
						that.key = '';
						that.new_meg = false;
						that.error_show=false
						// 扫码
						uni.scanCode({
							// onlyFromCamera: true,
							success: (res) => {
								const result = res.result;
								// 如果二维码里有http,则为二码合一设备，否则不是二码合一
								if (result.slice(0, 4) == 'http') {
									const params = result.split('?')[1].split('&');
									that.scanMac = params[0].split('=')[1];
									that.deviceNumber = params[1].split('=')[1];
								} else {
									that.scanMac = result.split(',')[0];
									that.deviceNumber = result.split(',')[1];
								}
								console.log('扫码时的scanMac', that.scanMac);
								console.log('扫码时的deviceNumber', that.deviceNumber);
								//查询阈值
								aesDecryptGetAPiyuzhi({
									devicenono: that.deviceNumber
								}).then((res) => {
									console.log('阈值', res);
									if (res.code == 801) {
										uni.showToast({
											title: '该设备未录入阈值，无法输出结果',
											icon: 'error',
											duration: 2000
										});
									} else {
										// 查询关联关系
										GetReleted({
											devceno: that.deviceNumber,
											IsTask: true
										}).then((res) => {
											console.log(res);
											that.get_result = true;
											console.log('当前get_result', that.get_result);
											if (res.code == 801) {
												if (that.$store.state.account == '') {
													uni.showToast({
														title: '请填写用户手机号',
														icon: 'none',
														duration: 2000
													});
													that.get_result = false;
													return;
												}
											} else {
												that.$store.commit('$uStore', {
													name: 'account',
													value: res.data.phone
												});
											}
											if (res.code == 801 || res.code == 803) {
												// 没有关联关系
												that.new_meg = true;
												that.initBlue();
											} else {
												that.get_result = false;
												// 已有关联
												let phoneNum = res.data.phone;
												if (phoneNum == that.$store.state.account) {
													if (res.data.detectionresult == 3) {
														// 检测未完成
														that.weiwancheng = true;
														that.initBlue();
													} else {
														//已经成功上传的数据
														console.log('后台存在数据，直接显示数据', res.data.detectionresult);
														uni.hideLoading();
														let arg1 = res.data.detectionresult;
														that.step = 7;
														const info = that.stepData[that.step - 1];
														const updatedInfo = Object.assign({}, info, { result: arg1 });

														if (arg1 === 0) {
															updatedInfo.operateName = '返回';
															that.info = updatedInfo;
															that.$refs.popup2.open('center');
														} else if (arg1 === 1) {
															that.info = updatedInfo;
															that.$refs.popup.open('center');
														} else {
															updatedInfo.operateName = '返回';
															that.info = updatedInfo;
														}
													}
												} else {
													// 已被绑定
													uni.showToast({
														title: '本设备已被绑定',
														icon: 'error',
														duration: 2000
													});
												}
											}
										});
									}
								});
							}
						});
					}
				}
			} else if (that.step === 2) {
				// 扫一扫
				console.log('扫一扫');
				that.step = 1;
				that.info = that.stepData[that.step - 1];
			} else if (that.step === 3) {
				that.read(HANDLE_0x9003);
				that.step++;
				that.info = that.stepData[that.step - 1];
			} else if (that.step === 4) {
				console.log(that.deviceId + '==>', HANDLE_0x9000);
				that.step++;
				that.info = that.stepData[that.step - 1];
			} else if (that.step === 5) {
				// 开始检测
				that.getServices(); // 检测是否断开
				if (that.resultTimer) {
					clearInterval(that.resultTimer);
				}
				that.step = 6;
				that.info = that.stepData[that.step - 1];
				that.read(HANDLE_0x9004);
			} else if (that.step === 7) {
				uni.navigateBack();
				that.close();
			}
		}, 500),
		//软关机
		Shutdown() {
			console.log('关机');
			uni.showModal({
				title: '提示',
				content: '确认关机',
				success: function (res) {
					if (res.confirm) {
						console.log('用户点击确认关机');
						that.send_2(HANDLE_0x9004);
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});

			console.log('触发软关机');
		},
		onAdapter() {
			console.log('启动-适配器-监听器');
			uni.onBluetoothAdapterStateChange((e) => {
				console.log('监听到适配器的状态 =》', JSON.stringify(e));
				this.bleAdapter = e;
				if (e.available === false && this.isBack === false) {
					// 扫一扫
					this.bleConnection = false;
					this.step = 1;
					this.info = this.stepData[this.step - 1];
					console.log('适配器不可用');
					// #ifdef MP-WEIXIN
					uni.showToast({
						title: `蓝牙适配器不可用`,
						icon: 'none',
						duration: 2000
					});
					// #endif
					uni.closeBluetoothAdapter({
						success: (res) => {
							console.log('关闭蓝牙适配器成功');
							console.log(res);
						}
					});
				}
			});
		},
		// 初始化
		initBlue() {
			if (this.isStartDiscovery) {
				uni.stopBluetoothDevicesDiscovery({
					success: (res) => {
						console.log('停止搜索');
						console.log(res);
					}
				});
			}
			uni.openBluetoothAdapter({
				success: (res) => {
					console.log('初始化蓝牙成功', res);
					this.bleAdapter = {
						available: true
					};
					this.onAdapter();
					this.discovery();
				},
				fail: (err) => {
					uni.showModal({
						title: '提示',
						content: '请开启手机蓝牙！',
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.openSetting({
									success: function (res) {
										// 在成功回调中判断用户是否已开启蓝牙权限，并进行相应处理
										if (res.authSetting['scope.bluetooth']) {
											// 用户已开启位置权限，可以重新调用 initBlue 获取蓝牙信息
											console.log('调用');
											that.initBlue();
										}
									}
								});
							}
						}
					});
					console.log('初始化蓝牙失败');
					console.error(err);
				}
			});
		},
		// 开始搜寻附近设备
		discovery() {
			if (!this.bleAdapter.available) {
				this.initBlue();
				return;
			}
			uni.startBluetoothDevicesDiscovery({
				// allowDuplicatesKey: true,
				services: ['00009000-0000-1000-8000-00805F9B34FB'],
				success: (res) => {
					this.isStartDiscovery = true;
					console.log('开始搜索');
					setTimeout(() => {
						if (this.isStartDiscovery) {
							this.stopDiscovery();
							uni.showToast({
								title: '未找到蓝牙设备',
								icon: 'none'
							});
							console.log('111');
							this.get_result = false;
						}
					}, 20000);
					// 开启监听回调
					this.executeMethods();
					// uni.onBluetoothDeviceFound(this.found)
				},
				fail: (err) => {
					this.isStartDiscovery = false;
					console.log('搜索失败');
					console.error(err);
				}
			});
		},
		// 找到新设备就触发该方法
		found(res) {
			// console.log(res,'found测试');
			if (res.devices[0].advertisData) {
				if (!this.blueDeviceList.find((item) => item.deviceId === res.devices[0].deviceId)) {
					this.blueDeviceList.push(res.devices[0]);
				}
			}
			console.log('当前设备数组', this.blueDeviceList);
		},
		//附近设备
		executeMethods() {
			// 开启监听回调
			uni.onBluetoothDeviceFound(this.found);
			uni.showToast({
				title: '正在搜索蓝牙...',
				icon: 'none',
				duration: 20000
			});
			// 3秒后执行方法2
			setTimeout(() => {
				console.log(this.blueDeviceList, '找到设备');
				console.log('当前设备编号', this.scanMac);
				this.blueDeviceList.forEach((item) => {
					console.log(item);
					// console.log((item.localName).substring(3),'遍历设备号');
					if (item.localName.substring(3) == this.scanMac) {
						this.blueDeviceList_1.push(item);
						console.log('配对成功', this.blueDeviceList_1);
						this.stopDiscovery();
						//开始连接
						this.setConnect();
					}
				});
			}, 3000);
		},
		// 循环设备列表，找到对应的设备
		setConnect() {
			console.log('启动循环');
			this.blueDeviceList_1.forEach((item) => {
				// console.log(item, '当前设备信息');
				// console.log('循环中', item.advertisData, item.advertisServiceUUIDs);
				// if (item.advertisData && item.advertisServiceUUIDs) {
				const uuid = item.advertisServiceUUIDs[0];
				// console.log('service uuid =', uuid, 'deviceId ', item.deviceId);
				const advertisData = ab2hex(item.advertisData);
				// console.log(advertisData, '解密后的advertisData');
				const mac = advertisData.toUpperCase();
				// console.log('当前mac', mac, mac.length);
				if (mac.length == 24) {
					// console.log('mac = ', mac);
					// console.log('当前信号强弱', item.RSSI);
					DecryptMac({
						macCode: mac
					}).then((res) => {
						console.log(res);
						if (res.code == 200) {
							const mac_base64 = res.data;
							if (mac_base64.includes(this.scanMac)) {
								console.log('绑定机链接');
								uni.showToast({
									title: '正在连接..',
									icon: 'success',
									duration: 2000
								});
								this.bleConnect(item);
								this.blueDeviceList_1 = [];
							}
						}
					});
				}
			});
		},
		// 连接蓝牙
		async bleConnect(data) {
			uni.createBLEConnection({
				deviceId: data.deviceId,
				success: async (res) => {
					console.log('连接时状态', this.weiwancheng);
					uni.showToast({
						title: `与蓝牙设备连接成功`,
						icon: 'success',
						duration: 2000
					});
					// 2秒后页面切换到（连接成功开始检测）
					setTimeout(() => {
						if (this.weiwancheng == false) {
							if(this.error_show==true){
								return
							}
							if (this.JG == false) {
								if (this.JG_2 == 1) {
									this.step = 6;
									this.info = this.stepData[this.step - 1];
									this.get_result = false;
								} else {
									this.step = 3;
									this.info = this.stepData[this.step - 1];
									this.get_result = false;
								}
							}
						}
					}, 2000);

					this.deviceId = data.deviceId;
					this.serviceId = HANDLE_0x9000;
					this.DetectionType = data.localName;

					if (that.new_meg == true) {
						//我把上面扫描二维码查询后台返回801时的代码放在了这里,在蓝牙连接成功后再在后台创建检测未完成结果
						console.log('连接蓝牙后的scanMac', that.scanMac);
						console.log('连接蓝牙后的deviceNumber', that.deviceNumber);
						console.log('创建检测记录');
						const city = that.$store.state.vx_city;
						if(that.$store.state.sex==''||that.$store.state.sex==null){
							that.$store.commit('$uStore', {
								name: 'age',
								value: 0
							});
						}
						CreateReleted({
							deviceNo: that.deviceNumber,
							macNo: that.scanMac,
							phone: that.$store.state.account,
							province: city.province,
							city: city.city,
							county: city.district,
							address: city.address,
							street: city.township,
							type: '掌上艾防小程序',
							age:that.$store.state.age,
							sex:that.$store.state.sex,
							managePhone:that.$store.state.docterphone,
							homeAddress:that.$store.state.homeAddress,
							name:that.$store.state.name
						}).then((res2) => {
							console.log(res2);
							if (res2.code == 200) {
							}
						});
					}

					this.getServices();
				},
				fail: (err) => {
					console.log(err);
					if (err.errno === 1509007) {
						uni.showToast({
							title: `蓝牙设备已连接`,
							icon: 'success',
							duration: 2000
						});
						this.getServices();
					} else {
						// 扫一扫
						this.step = 1;
						this.info = this.stepData[this.step - 1];
						console.log('连接失败');
						uni.showToast({
							title: `与蓝牙设备连接失败`,
							icon: 'none',
							duration: 2000
						});
						console.error(err);
					}
				}
			});
		},
		// 停止搜索
		stopDiscovery() {
			uni.stopBluetoothDevicesDiscovery({
				success: (res) => {
					this.isStartDiscovery = false;
					console.log('停止成功');
					console.log(res);
				},
				fail: (err) => {
					console.log('停止失败');
					console.error(err);
				}
			});
		},
		// 获取服务
		getServices() {
			uni.getBLEDeviceServices({
				deviceId: this.deviceId, // 设备ID，在上一步【4】里获取
				success: async (res) => {
					console.log(this.deviceId + ' getBLEDeviceServices => ', res);
					this.getCharacteristics();
				},
				fail: (err) => {
					console.error(err);
					if (this.checkTimer) {
						clearInterval(this.checkTimer);
						this.checkTimer = null;
					}
					if (this.timer) {
						clearInterval(this.timer);
						this.timer = null;
					}
					if ([-1, 10000, 10002, 10003, 10004, 10005, 10006].includes(err.errCode)) {
						this.close();
						uni.showModal({
							content: '请检查设备是否正常运行，或重新扫描连接，如果设备显示红灯，请更换设备。',
							showCancel: false,
							success(res) {
								if (res.confirm) {
									// 扫一扫
									that.step = 1;
									that.info = that.stepData[that.step - 1];
								}
							}
						});
					}
				}
			});
		},

		// 获取特征值
		getCharacteristics() {
			uni.getBLEDeviceCharacteristics({
				deviceId: this.deviceId, // 设备ID
				serviceId: this.serviceId, // 服务UUID
				success: (res) => {
					console.log(this.serviceId + 'characteristics =', res);
					if (this.key == '') {
						this.read(HANDLE_0x9003);
					}

					if (this.resultTimer) {
						clearInterval(this.resultTimer);
					}
					this.read(HANDLE_0x9004);
				},
				fail: (err) => {
					console.error(err);
					if ([10002, 10003, 10006].includes(err.errCode)) {
						this.close();
						uni.showModal({
							content: '请检查设备是否正常运行，或重新扫描连接。',
							showCancel: false,
							success(res) {
								if (res.confirm) {
									// 扫一扫
									that.step = 1;
									that.info = that.stepData[that.step - 1];
								}
							}
						});
					}
				}
			});
		},
		// 监听消息变化
		listenValueChange() {
			if (this.up_type == true) {
				return;
			}
			uni.onBLECharacteristicValueChange(async (res) => {
				// console.log('onBLECharacteristicValueChange', res)
				// 结果里有个value值，该值为 ArrayBuffer 类型，所以在控制台无法用肉眼观察到，必须将该值转换为16进制
				// console.log('不解密', res.value);
				const resHex = ab2hex(res.value);
				// console.log('ab2hex ===', resHex)
				if (res.characteristicId === HANDLE_0x9001) {
					const data = await this.aesDecrypt(resHex, '0x9001');
					console.log('读取结果：0x9001返回的版本号' + data);
					// 句柄0x9002对应检测项目(ASCII码16个字节)，
				} else if (res.characteristicId === HANDLE_0x9002) {
					const data = await this.aesDecrypt(resHex, '0x9002');
					console.log('读取结果：0x9002返回的检测项目' + data);
					// 句柄0x9003对应批次号(ASCII码8个字节)，
				} else if (res.characteristicId === HANDLE_0x9003) {
					// const data = await this.aesDecrypt(resHex, '0x9003')
					// console.log("读取结果：0x9003返回的批次号" + data);
					const num = resHex.substr(-18);
					this.key = baseSecret + num;
					console.log('读取结果：0x9003返回的key=>>>>> ', this.key);
					this.read(HANDLE_0x9001);
					// 句柄0x9004对应检测状态(1个字节)，
				} else if (res.characteristicId === HANDLE_0x9004 && that.up_type == false) {
					if (that.key == '') {
						that.read(HANDLE_0x9003);
					}
					const data = await this.aesDecrypt(resHex, '0x9004');
					console.log('读取结果：0x9004返回的检测状态' + data);
					// await this.read(HANDLE_0x9006)
					if (this.weiwancheng == true) {
						this.step = 6;
						this.info = this.stepData[this.step - 1];
						if (1 === data) {
							console.log('读取结果：0x9004返回的=' + data + '=已开始检测，继续读取倒计时');
							this.read(HANDLE_0x9007); // 读取结果：0x9007返回的检测结果剩余时间
							if (this.checkTimer) {
								clearInterval(this.checkTimer);
								this.checkTimer = null;
							}
						} else if (2 === data) {
							console.log('读取结果：0x9004返回的=' + data + '=30分钟未加样！！');
							this.step = 7;
							const info = this.stepData[this.step - 1];
							let arg1 = 4;
							this.info = Object.assign({}, info, {
								result: arg1,
								operateName: '返回'
							});
							this.stopBluetooth();
						} else if (4 === data) {
							console.log('读取结果：0x9004返回的=' + data + '=设备异常！！');
							this.step = 7;
							const info = this.stepData[this.step - 1];
							let arg1 = 4;
							this.info = Object.assign({}, info, {
								result: arg1,
								operateName: '返回'
							});
							this.stopBluetooth();
						} else {
							this.times = -1;
							console.log('读取结果：0x9004返回的：' + data + '==' + (0 === data ? '未开始检测' : '未知状态') + ',等待5秒后重新查询状态');
							if (this.resultTimer) {
								clearTimeout(this.resultTimer);
								this.resultTimer = null;
							}
							if (this.checkTimer) {
								clearInterval(this.checkTimer);
								this.checkTimer = null;
							}
							this.resultTimer = setTimeout(async () => {
								this.read(HANDLE_0x9004);
							}, 5000);
							this.checkTimer = setInterval(() => {
								this.getServices();
							}, 2000);
						}
					} else {
						if (1 === data) {
							console.log('读取结果：0x9004返回的=' + data + '=已开始检测，继续读取倒计时');
							this.JG_2 = data;
							this.read(HANDLE_0x9007); // 读取结果：0x9007返回的检测结果剩余时间
							if (this.checkTimer) {
								clearInterval(this.checkTimer);
								this.checkTimer = null;
							}
						} else if (2 === data) {
							this.error_show=true
							console.log('读取结果：0x9004返回的=' + data + '=30分钟未加样！！');
							this.step = 7;
							const info = this.stepData[this.step - 1];
							let arg1 = 4;
							this.info = Object.assign({}, info, {
								result: arg1,
								operateName: '返回'
							});
							this.stopBluetooth();
						} else if (4 === data) {
							this.error_show=true
							console.log('读取结果：0x9004返回的=' + data + '=设备异常！！');
							this.step = 7;
							const info = this.stepData[this.step - 1];
							let arg1 = 4;
							this.info = Object.assign({}, info, {
								result: arg1,
								operateName: '返回'
							});
							this.stopBluetooth();
						} else {
							this.times = -1;
							console.log('读取结果：0x9004返回的：' + data + '==' + (0 === data ? '未开始检测' : '未知状态') + ',等待5秒后重新查询状态');
							if (this.resultTimer) {
								clearTimeout(this.resultTimer);
								this.resultTimer = null;
							}
							if (this.checkTimer) {
								clearInterval(this.checkTimer);
								this.checkTimer = null;
							}
							this.resultTimer = setTimeout(async () => {
								this.read(HANDLE_0x9004);
							}, 5000);
							this.checkTimer = setInterval(() => {
								this.getServices();
							}, 2000);
						}
					}

					// 句柄0x9005对应检测结果(5个字节，1个字节为结果，四个字节为过程数据)，结果为0为阴性，1为阳性，2为异常。
				} else if (res.characteristicId === HANDLE_0x9005) {
					console.log('9005X返回原始数据', resHex);
					const data = await this.aesDecrypt(resHex, '0x9005');
					if (data.arg3 == false) {
						this.read(HANDLE_0x9005);
					} else {
						let arg1 = data.arg1 === 128 ? 0 : data.arg1 === 129 ? 1 : data.arg1; // 如果是128，默认是0；如果是129，默认是1；否则保持原值
						const arg2 = data.arg1 === 128 ? 0 : data.arg1 === 129 ? 1 : data.arg1; // 同样的处理逻辑
						// let arg1 = data.arg1; // 0 阴性 1 阳性 2 异常 4 设备异常
						// const arg2 = data.arg1; // 0 阴性 1 阳性 2 异常 4 设备异常
						console.log('读取结果：0x9005返回的检测结果' + arg1);

						// 获取结果值
						await aesDecryptjieguozhi({
							Data: resHex,
							Key: this.key,
							Handle: '0x9005'
						}).then((res) => {
							this.$store.commit('$uStore', {
								name: 'jieguozhi',
								value: res.data.jieguozhi
								// value:-28000
							});
							console.log('存入的结果值', this.$store.state.jieguozhi);
						});
						//动态阈值
						await aesDecryptGetAPiyuzhi({
							devicenono: this.deviceNumber
						}).then((res) => {
							console.log('阈值', res);
							if (res.code == 801) {
								uni.showToast({
									title: '该设备未录入阈值，无法输出结果',
									icon: 'error',
									duration: 2000
								});
							} else {
								if (this.$store.state.jieguozhi > 35000 || this.$store.state.jieguozhi < -4500) {
									arg1 = 4;
									console.log('结果值大于35000');
								} else if (arg1 !== 4 && arg1 !== 2) {
									if (res.data[0].yuzhi > this.$store.state.jieguozhi) {
										console.log('结果值小于与阈值，阴性');
										arg1 = 0;
									} else if (res.data[0].yuzhi <= this.$store.state.jieguozhi) {
										console.log('结果值大于与阈值，阳性');
										arg1 = 1;
									}
								}
							}
						});

						this.stopBluetooth();
						// 将假阈值跟结果值进行比较，如果结果值小于阈值，则是无反应；结果值大于阈值，
						// 则是有反应；如果拿不到假阈值（返回NULL）,则继续当前的逻辑
						this.step = 7;
						const info = this.stepData[this.step - 1];
						if (arg1 === 1) {
							this.info = Object.assign({}, info, {
								result: arg1
							});
						} else {
							this.info = Object.assign({}, info, {
								result: arg1,
								operateName: '返回'
							});
						}
						const city = this.$store.state.vx_city;
						let yuzhi = this.$store.state.yuzhi.toString();
						let jieguozhi = this.$store.state.jieguozhi.toString();
						console.log(yuzhi);
						const res = await UpReagentResult({
							deviceNo: this.deviceNumber,
							macNo: this.scanMac,
							detectionType: this.DetectionType,
							phone: this.$store.state.account,
							province: city.province,
							city: city.city,
							county: city.district,
							address: city.address,
							street: city.township,
							detectionResult: arg1, //判断过的数据
							realDetectionResult: arg2, //真实数据
							yuzhi: yuzhi,
							jieguozhi: jieguozhi,
							type: '掌上艾防小程序'
						});
						if (res.code === 200 || res.code === 801) {
							// console.log('上报成功结果 ===》', res.Data);

							if (res.message == '修改成功！') {
								// uni.showModal({
								// 	title: '订阅消息弹窗',
								// 	content: '是否要订阅消息提醒？',
								// 	success: function (res1) {
								// 		if (res1.confirm) {
								// 			uni.requestSubscribeMessage({
								// 				tmplIds: ['DRuf9QMQ0TcxQDYAZCLNjYhGINKk3-gjABWh-X9O-S0'],
								// 				success(res2) {
								// 					console.log(res2, '订阅接口同意成功');
								// 					console.log(this);
								// 					if (arg1 === 1) {
								// 						that.$refs.popup.open('center');
								// 					}
								// 					if (arg1 === 0) {
								// 						that.$refs.popup2.open('center');
								// 					}
								// 					let time = '';
								// 					let result2 = '';
								// 					if (arg1 == 0) {
								// 						let dateTime = new Date();
								// 						dateTime = dateTime.setDate(dateTime.getDate() + 90);
								// 						dateTime = new Date(dateTime);
								// 						time = that.formatTime(dateTime);
								// 						result2 = '试剂检测无反应';
								// 						tips = '距上次检测90天，请再次检测获取健康报告';
								// 					}
								// 					if (arg1 == 1) {
								// 						let dateTime = new Date();
								// 						dateTime = dateTime.setDate(dateTime.getDate() + 28);
								// 						dateTime = new Date(dateTime);
								// 						time = that.formatTime(dateTime);
								// 						result2 = '试剂检测有反应';
								// 						tips = '距上次检测28天，请再次检测获取健康报告';
								// 					}
								// 					InsertSubscribeinform({
								// 						InformTemplateId: 'DRuf9QMQ0TcxQDYAZCLNjYhGINKk3-gjABWh-X9O-S0',
								// 						ToUser: that.$store.state.vx_openId,
								// 						Item: result2,
								// 						OperationDataId: that.OperationDataId + '',
								// 						SendTime: time,
								// 						Data: JSON.stringify({
								// 							data: {
								// 								thing5: {
								// 									value: '艾瑞测'
								// 								},
								// 								phrase4: {
								// 									value: '已完成'
								// 								},
								// 								time16: {
								// 									value: time
								// 								},
								// 								thing7: {
								// 									value: tips
								// 								}
								// 							}
								// 						})
								// 					});
								// 				},
								// 				fail(res2) {
								// 					console.log(res2, '订阅接口同意错误');
								// 				}
								// 			});
								// 		} else {
								if (arg1 === 1) {
									that.$refs.popup.open('center');
								}
								if (arg1 === 0) {
									that.$refs.popup2.open('center');
								}
								// 			console.log('点击了取消');
								// 		}
								// 	}
								// });
							}
						}
					}

					// 句柄0x9006对应检测开始时间(4个字节，单位为秒，未开始为0，结束为0xffffffff)，
				} else if (res.characteristicId === HANDLE_0x9006) {
					// const data = await this.aesDecrypt(resHex, '0x9006');
					// console.log("读取结果：0x9006返回" + data);
					await aesDecrypt2({
						Data: resHex,
						Key: this.key,
						Handle: '0x9006'
					}).then((res) => {
						this.$store.commit('$uStore', {
							name: 'yuzhi',
							value: res.data.yz
						});
						console.log('存入的阈值', this.$store.state.yuzhi);
					});

					// 句柄0x9007对应检测结果剩余时间(4个字节，单位为秒，未开始为0xffffffff，结束为0)。
				} else if (res.characteristicId === HANDLE_0x9007) {
					const data = await this.aesDecrypt(resHex, '0x9007');
					console.log('读取结果：0x9007返回的检测结果剩余时间' + data);
					this.times = data;
					let end = Date.now() + (data + 1) * 1000;
					// 倒计时结束请求获取结果
					let times = data;
					let text = data;
					if (this.timer) {
						clearInterval(this.timer);
						this.timer = null;
					}
					console.log('当前时间戳', Date.now() + '==' + end);
					this.timer = setInterval(async () => {
						this.HFX = times;
						times = parseInt((end - Date.now()) / 1000);
						console.log('倒计时', times);
						// console.log('测试倒计时', text);
						this.getServices();
						if (times <= 0) {
							times = 0;
							clearInterval(this.timer);
							this.timer = null;
							// 开始读取过程值
							this.processIndex = 0;
							this.JG = true;
							this.read(HANDLE_0x9006);
							// this.read(HANDLE_0x9005);
							this.send('HANDLE_0x9005');
							this.up_type = true;
						}
					}, 1000);
				}
			});
		},
		async startWriteProgress() {
			console.log('startWriteProgress ', this.processIndex);
			await this.send(HANDLE_0x9005, this.processIndex);
			this.read(HANDLE_0x9005);
		},

		// aes解密方法
		async aesDecrypt(word, handle) {
			const res = await AESDecrypt({
				Data: word,
				Key: this.key,
				Handle: handle,
				deviceno: this.deviceNumber
			});
			if (res.code === 200) {
				return res.data;
			}
		},
		// aes加密方法
		async aesEncrypt(word) {
			const res = await AESEncrypt({
				Data: word,
				Key: this.key
			});
			if (res.code === 200) {
				return res.data;
			}
		},
		// 向设备发送数据
		async send(characteristicId, type = 0) {
			let that = this;
			console.log(`写入${characteristicId}，值为${type}`);
			let Data = '';
			if (type === 0) {
				Data = '00000000000000000000000000000000';
			} else {
				Data = '10000000000000000000000000000000';
			}
			const res = await AESEncrypt({
				Data,
				Key: this.key
			});
			console.log('写入', Data, res.data);
			let textkey = res.data.toUpperCase();
			console.log(textkey);
			if (res.code === 200) {
				// const buffer = new ArrayBuffer(res.Data);
				const buffer = this.hexStringToArrayBuffer(textkey);
				console.log(buffer, '命令值');
				console.log('当前特征值', characteristicId);
				uni.writeBLECharacteristicValue({
					deviceId: this.deviceId, // 设备ID，在【4】里获取到
					serviceId: this.serviceId, // 服务UUID，在【6】里能获取到
					characteristicId: '00009005-0000-1000-8000-00805F9B34FB', // 特征值，在【7】里能获取到
					value: buffer,
					success: async (res) => {
						that.read(HANDLE_0x9005);
						console.log('写入HANDLE_0x9005的0指令发送成功', res);
						await sleep(100);
						await that.getCharacteristics();
					},
					fail: (err) => {
						console.log('写入指令发送失败', err);
					}
				});
			}
		},
		hexStringToArrayBuffer(hexString) {
			const hex = hexString.replace(/\s/g, ''); // 移除空格
			const bytes = new Uint8Array(hex.length / 2);
			for (let i = 0; i < hex.length; i += 2) {
				bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
			}
			return bytes.buffer;
		},
		async send_2(characteristicId) {
			console.log(`写入${characteristicId}`);
			let Data = '';
			Data = '73687574000000000000000000000000';
			const res = await AESEncrypt({
				Data,
				Key: this.key
			});
			let closekey = res.data.toUpperCase();
			console.log(closekey.toUpperCase());
			if (res.code === 200) {
				// 向蓝牙设备发送一个0x00的16进制数据
				// const buffer = new ArrayBuffer(closekey)
				const buffer = this.hexStringToArrayBuffer(closekey);
				console.log(buffer, '命令值');

				uni.writeBLECharacteristicValue({
					deviceId: this.deviceId, // 设备ID，在【4】里获取到
					serviceId: this.serviceId, // 服务UUID，在【6】里能获取到
					characteristicId, // 特征值，在【7】里能获取到
					value: buffer,
					writeType: 'write',
					success: async (res) => {
						this.$refs.popup.close();
						console.log('写入指令发送成功', res);
					},
					fail: (err) => {
						console.log('写入指令发送失败', err);
					}
				});
			}
		},
		// 【11】读取数据
		read(characteristicId) {
			console.log('read ', this.deviceId, this.serviceId, characteristicId);
			uni.readBLECharacteristicValue({
				deviceId: this.deviceId,
				serviceId: this.serviceId,
				characteristicId,
				success: (res) => {
					// console.log('读取指令发送成功')
					// 接受消息的方法
					this.listenValueChange();
				},
				fail: (err) => {
					console.log('读取指令发送失败', err);
				}
			});
		},
		//停止消息监听
		stopBluetooth(characteristicId) {
			// 停止监听蓝牙特征值变化
			uni.offBLECharacteristicValueChange();
			console.log('停止获取蓝牙特征值');
		},
		async close() {
			this.times = 0;
			if (this.resultTimer) {
				clearInterval(this.resultTimer);
				this.resultTimer = null;
			}
			if (this.timer) {
				clearInterval(this.timer);
				this.timer = null;
			}
			if (this.checkTimer) {
				clearInterval(this.checkTimer);
				this.checkTimer = null;
			}
			// if (this.processTimer) {
			//   clearTimeout(this.processTimer)
			//   this.processTimer = null
			// }
			if (this.$refs.testCheck) {
				this.$refs.testCheck.getReset();
			}
			this.$refs.popup.close();
			//断开蓝牙连接
			uni.closeBLEConnection({
				//设备ID
				deviceId: this.deviceId,
				success(res) {
					console.log('断开蓝牙连接', res);
				}
			});
			sleep(1000);
			//关闭蓝牙模块
			uni.closeBluetoothAdapter({
				success(res) {
					console.log('关闭蓝牙模块', res);
				}
			});
			sleep(1000);
		},
		async onCancel() {
			const res = await UpdateReagentResult({
				deviceno: this.deviceNumber,
				phone: this.$store.state.account,
				isneedcontact: false
			});
			if (res.code === 200) {
				this.close();
				this.$refs.popup.close();
			} else {
				this.$refs.popup.close();
			}
		},
		async onNeed() {
			const res = await UpdateReagentResult({
				deviceno: this.deviceNumber,
				phone: this.$store.state.account,
				isneedcontact: true
			});
			if (res.code === 200) {
				this.close();
				this.$refs.popup.close();
				uni.navigateTo({
					url: '/page_airuice/hospital/index'
				});
			} else {
				this.$refs.popup.close();
				// uni.navigateTo({
				// 	url: '/page_airuice/hospital/index'
				// });
			}
		},
		// 获取当前位置
		getLocation(tag) {
			uni.getLocation({
				type: 'wgs84',
				success: async (res) => {
					//res.longitude,res.latitude分别为当前经度，纬度
					ConvertCoordinate({
						Locations: [res.longitude, res.latitude].join(',')
					}).then((res) => {
						if (res.code === 200) {
							console.log('定位返回', res.data.regeocode);
							const { province, city, district, township } = res.data.regeocode.addresscomponent;
							const address = res.data.regeocode.formatted_address;
							this.$store.commit('$uStore', {
								name: 'vx_city',
								value: {
									province,
									city,
									district,
									township,
									address
								}
							});
							console.log('当前省份', this.$store.state.vx_city.province);
							this.gps = true;
							console.log(this.gps);
						}
					});
				},
				fail: (err) => {
					console.log(err);
					this.gps = false;
					uni.showModal({
						title: '提示',
						content: '使用本设备时，请开启手机定位！',
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.openSetting({
									success: function (res) {
										// scope.bluetooth
										// 在成功回调中判断用户是否已开启位置权限，并进行相应处理
										if (res.authSetting['scope.userLocation']) {
											// 用户已开启位置权限，可以重新调用 uni.getLocation 获取位置信息
											console.log('调用');
										}
									}
								});
							}
						}
					});
				}
			});
		},
		formatTime(dateTime) {
			var y = dateTime.getFullYear();
			var m = dateTime.getMonth() + 1;
			m = m < 10 ? '0' + m : m;
			var d = dateTime.getDate();
			d = d < 10 ? '0' + d : d;
			var h = dateTime.getHours();
			var minute = dateTime.getMinutes();
			minute = minute < 10 ? '0' + minute : minute;
			var s = dateTime.getSeconds();
			s = s < 10 ? '0' + s : s;
			let time = y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + s;
			return time;
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	width: 100vw;
	height: 100vh;
	width: 100%;
	background-color: #30bac3;
	position: relative;
	display: flex;
	flex-direction: column;

	.nav-style {
		position: fixed;
		top: 0;
		right: 0;
		left: 0;
		z-index: 1000;
		display: flex;
		padding-left: 23rpx;
		align-items: center;
		justify-content: center;

		.small-logo {
			position: absolute;
			width: 100rpx;
			height: 35rpx;
			left: 45%;
		}

		.back-img {
			width: 36rpx;
			height: 36rpx;
			position: absolute;
			left: 23rpx;
			bottom: 0;
			margin: auto;
		}
	}

	.process-wrap {
		padding-bottom: 50rpx;
		box-sizing: border-box;
	}

	.wrap {
		flex: 1;
		width: 100%;
		margin-top: 36rpx;
		overflow: hidden;
	}

	.popup-wrap {
		width: 615.38rpx;
		height: 1000rpx;
		padding: 42rpx;
		box-sizing: border-box;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;

		.popup-bg {
			width: 615.38rpx;
			height: 1000rpx;
			position: absolute;
			border-radius: 30rpx;
			top: 0;
			left: 0;
			z-index: 0;
		}

		.popup-container {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.popup-title {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			text-align: center;
			margin-top: 34rpx;

			.popup-img {
				width: 130rpx;
				height: 150rpx;
			}

			.popup-text {
				margin-top: 20rpx;
				margin-left: 22rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #000000;
			}
		}

		.popup-content {
			width: 515rpx;
			height: 450rpx;
			overflow-y: scroll;
			margin: 35rpx auto;
			font-size: 27rpx;
			font-weight: 400;
			color: #333333;
			line-height: 40rpx;
			text-align: center;
		}

		.popup-btn-wrap {
			width: 540.38rpx;
			// position: absolute;
			// left: 0;
			// right: 0;
			// bottom: 42rpx;
			margin: auto;
			// display: flex;
			// justify-content: space-between;
		}

		.popup-btn {
			width: 250rpx;
			height: 85rpx;
			line-height: 85rpx;
			font-size: 28rpx;
			font-weight: 400;
			text-align: center;
			border-radius: 15rpx;
			margin: 0 auto;

			&.cancel {
				color: #333333;
				background: #ebebed;
			}

			&.need {
				background: #30bac3;
				color: #ffffff;
			}
		}

		.popup-btn-close {
			width: 230rpx;
			height: 85rpx;
			line-height: 85rpx;
			font-size: 28rpx;
			font-weight: 400;
			text-align: center;
			border-radius: 15rpx;
			margin-left: 10rpx;

			&.cancel {
				color: #333333;
				background: #ebebed;
			}
		}
	}

	.popup-wrap2 {
		width: 615.38rpx;
		height: 840rpx;
		padding: 42rpx;
		box-sizing: border-box;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;

		.popup-bg {
			width: 615.38rpx;
			height: 840rpx;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 0;
			border-radius: 30rpx;
		}

		.popup-container {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.popup-title {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			text-align: center;
			margin-top: 34rpx;

			.popup-img {
				width: 130rpx;
				height: 150rpx;
			}

			.popup-text {
				margin-top: 20rpx;
				margin-left: 22rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #000000;
			}
		}

		.popup-content {
			width: 515rpx;
			height: 380rpx;
			overflow-y: scroll;
			margin: 35rpx auto;
			font-size: 27rpx;
			font-weight: 400;
			color: #333333;
			line-height: 40rpx;
			text-align: center;
		}

		.popup-btn-wrap2 {
			width: 540.38rpx;
			// position: absolute;
			// left: 0;
			// right: 0;
			// bottom: 42rpx;
			margin: auto;
			display: flex;
			justify-content: center;

			.popup-btn-close {
				width: 230rpx;
				height: 85rpx;
				line-height: 85rpx;
				font-size: 28rpx;
				font-weight: 400;
				text-align: center;
				border-radius: 15rpx;
				// margin-left: 10rpx;
				color: #333333;
				background: #ebebed;
			}
		}
	}
}
</style>
